/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.ActionEvent
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.TextField
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.scene.text.Text
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.baseSetting.saleSchedule;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.business.ShopSortSettingUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.plugIn.searchTextField.SearchTextField;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.baseSetting.saleSchedule.ShopSortSettingController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.shopSortSetting.AddShopTableOutData;
import com.gys.data.shopSortSetting.GetShopDetailOutData;
import com.gys.data.shopSortSetting.GetShopSortOutData;
import com.gys.view.shopSort.AddShopSortView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddShopSortController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(AddShopSortController.class);
    @FXML
    private SearchTextField addGssgBrId;
    @FXML
    private TextField addGssgId;
    @FXML
    private AnchorPane pane;
    @FXML
    private Text title;
    @FXML
    private TextField addGssgBrName;
    @FXML
    private TextField addGssgName;
    @FXML
    private TableView<AddShopTableOutData> tableView;
    @FXML
    private TableColumn<AddShopTableOutData, String> shopName;
    @FXML
    private TableColumn<AddShopTableOutData, String> index;
    @FXML
    private TableColumn<AddShopTableOutData, String> shopId;
    private ObservableList<AddShopTableOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    @Autowired
    private ShopSortSettingController shopSortSettingController;
    Set<String> shopIdsSet = new HashSet<String>();
    private String shopIdSelect = "";
    public String titleTemp = "";
    public Boolean type = false;
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.addGssgBrId.setTextFieldPrefWeight(150.0);
        this.addGssgBrId.setTextFieldPrefHeight(30.0);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.title.setText(this.titleTemp);
        this.shopIdSelect = "";
        this.addGssgBrId.setText(null);
        this.addGssgId.clear();
        this.addGssgBrName.clear();
        this.addGssgName.clear();
        this.shopIdsSet = new HashSet<String>();
        this.tableView.getItems().clear();
        this.tableView.refresh();
        if (this.type.booleanValue()) {
            this.addGssgId.setDisable(false);
            this.addGssgName.setDisable(false);
        } else {
            this.addGssgId.setDisable(true);
            this.addGssgName.setDisable(true);
        }
        this.shopId.setCellValueFactory((Callback)new PropertyValueFactory(this.shopId.getId()));
        this.shopName.setCellValueFactory((Callback)new PropertyValueFactory(this.shopName.getId()));
        this.index.setCellValueFactory((Callback)new PropertyValueFactory(this.index.getId()));
        ArrayList<TextField> textFieldForm = new ArrayList<TextField>();
        textFieldForm.add(this.addGssgBrName);
        this.addGssgBrId.reLoadTextField(this.shopSortSettingController.words, this.shopSortSettingController.otherMap, textFieldForm);
        this.addGssgBrName.textProperty().addListener((observable, oldValue, newValue) -> {
            if (ObjectUtil.isNotEmpty(newValue) && !this.shopIdSelect.equals(this.addGssgBrId.getText())) {
                this.addShop();
            }
        });
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                AddShopSortView view = SpringUtil.getBean(AddShopSortView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.DELETE) {
                            AddShopTableOutData data = (AddShopTableOutData)AddShopSortController.this.tableView.getSelectionModel().getSelectedItem();
                            AddShopSortController.this.tableView.getItems().remove(data);
                            for (int i = 0; i < AddShopSortController.this.tableView.getItems().size(); ++i) {
                                ((AddShopTableOutData)AddShopSortController.this.tableView.getItems().get(i)).setIndex(String.valueOf(i + 1));
                            }
                            AddShopSortController.this.shopIdsSet.remove(data.getShopId());
                            AddShopSortController.this.tableView.refresh();
                        }
                        e.consume();
                    }
                });
            }
        }, 1000L);
        if (!this.type.booleanValue()) {
            this.initTableByEdit();
        }
    }

    private void initTableByEdit() {
        GetShopSortOutData getShopSortOutData = this.shopSortSettingController.selectShopSort;
        this.addGssgId.setText(getShopSortOutData.getGssgIdSort());
        this.addGssgName.setText(getShopSortOutData.getGssgNameSort());
        ObservableList<GetShopDetailOutData> detailOutData = this.shopSortSettingController.getDetailInfo().getItems();
        ArrayList addShopTableOutDataList = new ArrayList();
        detailOutData.forEach(item -> {
            AddShopTableOutData addShopTableOutData = new AddShopTableOutData();
            addShopTableOutData.setIndex(item.getIndexDetail().toString());
            addShopTableOutData.setShopId(item.getGssgBrIdDetail());
            addShopTableOutData.setShopName(item.getGssgBrNameDetail());
            addShopTableOutDataList.add(addShopTableOutData);
            this.shopIdsSet.add(item.getGssgBrIdDetail());
        });
        this.observableTableList = FXCollections.observableArrayList(addShopTableOutDataList);
        this.tableView.setItems(this.observableTableList);
        this.tableView.refresh();
    }

    @FXML
    private void saveAction(ActionEvent event) {
        if (!this.addSaveCheck()) {
            return;
        }
        if (this.type.booleanValue()) {
            this.addSave();
        } else {
            this.editSave();
        }
    }

    private void editSave() {
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("gssgId", this.addGssgId.getText());
        param.put("gssgName", this.addGssgName.getText());
        param.put("shops", this.tableView.getItems());
        HttpJson httpJson = ShopSortSettingUtil.editSave(param);
        if (httpJson.isSuccess()) {
            CommonUtil.handleHttpResOnlyAlert(httpJson, "\u66f4\u65b0\u6210\u529f");
            this.closeAction();
            this.shopSortSettingController.initSortTableView();
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
    }

    private void addSave() {
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("gssgId", this.addGssgId.getText());
        param.put("gssgName", this.addGssgName.getText());
        param.put("shops", this.tableView.getItems());
        HttpJson httpJson = ShopSortSettingUtil.add(param);
        if (httpJson.isSuccess()) {
            CommonUtil.handleHttpResOnlyAlert(httpJson, "\u4fdd\u5b58\u6210\u529f");
            this.closeAction();
            this.shopSortSettingController.initSortTableView();
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
    }

    public boolean addSaveCheck() {
        String message = "";
        if (ObjectUtil.isEmpty(this.addGssgId.getText())) {
            message = "\u5206\u7c7b\u7f16\u7801\u5fc5\u586b";
        } else if (ObjectUtil.isEmpty(this.addGssgName.getText())) {
            message = "\u5206\u7c7b\u540d\u79f0\u5fc5\u586b";
        } else if (ObjectUtil.isEmpty(this.tableView.getItems())) {
            message = "\u8bf7\u6dfb\u52a0\u95e8\u5e97";
        }
        if (ObjectUtil.isNotEmpty(message)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", message);
            alert.showAndWait();
            return false;
        }
        return true;
    }

    private void addShop() {
        if (!this.shopIdsSet.add(this.addGssgBrId.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8be5\u95e8\u5e97\u5df2\u5b58\u5728");
            alert.show();
            this.addGssgBrName.clear();
            this.shopIdSelect = "";
            return;
        }
        AddShopTableOutData addShopTableOutData = new AddShopTableOutData();
        addShopTableOutData.setShopId(this.addGssgBrId.getText());
        addShopTableOutData.setShopName(this.addGssgBrName.getText());
        addShopTableOutData.setIndex(this.tableView.getItems().size() + 1 + "");
        this.tableView.getItems().add(addShopTableOutData);
        this.tableView.refresh();
        this.shopIdSelect = this.addGssgBrId.getText();
        this.addGssgBrName.clear();
    }

    @FXML
    private void closeAction() {
        this.pane.getScene().getWindow().hide();
    }

    public SearchTextField getAddGssgBrId() {
        return this.addGssgBrId;
    }

    public TextField getAddGssgId() {
        return this.addGssgId;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public Text getTitle() {
        return this.title;
    }

    public TextField getAddGssgBrName() {
        return this.addGssgBrName;
    }

    public TextField getAddGssgName() {
        return this.addGssgName;
    }

    public TableView<AddShopTableOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<AddShopTableOutData, String> getShopName() {
        return this.shopName;
    }

    public TableColumn<AddShopTableOutData, String> getIndex() {
        return this.index;
    }

    public TableColumn<AddShopTableOutData, String> getShopId() {
        return this.shopId;
    }

    public ObservableList<AddShopTableOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public ShopSortSettingController getShopSortSettingController() {
        return this.shopSortSettingController;
    }

    public Set<String> getShopIdsSet() {
        return this.shopIdsSet;
    }

    public String getShopIdSelect() {
        return this.shopIdSelect;
    }

    public String getTitleTemp() {
        return this.titleTemp;
    }

    public Boolean getType() {
        return this.type;
    }

    public Timer getTimer() {
        return this.timer;
    }

    public void setAddGssgBrId(SearchTextField addGssgBrId) {
        this.addGssgBrId = addGssgBrId;
    }

    public void setAddGssgId(TextField addGssgId) {
        this.addGssgId = addGssgId;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setTitle(Text title) {
        this.title = title;
    }

    public void setAddGssgBrName(TextField addGssgBrName) {
        this.addGssgBrName = addGssgBrName;
    }

    public void setAddGssgName(TextField addGssgName) {
        this.addGssgName = addGssgName;
    }

    public void setTableView(TableView<AddShopTableOutData> tableView) {
        this.tableView = tableView;
    }

    public void setShopName(TableColumn<AddShopTableOutData, String> shopName) {
        this.shopName = shopName;
    }

    public void setIndex(TableColumn<AddShopTableOutData, String> index) {
        this.index = index;
    }

    public void setShopId(TableColumn<AddShopTableOutData, String> shopId) {
        this.shopId = shopId;
    }

    public void setObservableTableList(ObservableList<AddShopTableOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setShopSortSettingController(ShopSortSettingController shopSortSettingController) {
        this.shopSortSettingController = shopSortSettingController;
    }

    public void setShopIdsSet(Set<String> shopIdsSet) {
        this.shopIdsSet = shopIdsSet;
    }

    public void setShopIdSelect(String shopIdSelect) {
        this.shopIdSelect = shopIdSelect;
    }

    public void setTitleTemp(String titleTemp) {
        this.titleTemp = titleTemp;
    }

    public void setType(Boolean type) {
        this.type = type;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddShopSortController)) {
            return false;
        }
        AddShopSortController other = (AddShopSortController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        SearchTextField this$addGssgBrId = this.getAddGssgBrId();
        SearchTextField other$addGssgBrId = other.getAddGssgBrId();
        if (this$addGssgBrId == null ? other$addGssgBrId != null : !((this$addGssgBrId)).equals(other$addGssgBrId)) {
            return false;
        }
        TextField this$addGssgId = this.getAddGssgId();
        TextField other$addGssgId = other.getAddGssgId();
        if (this$addGssgId == null ? other$addGssgId != null : !this$addGssgId.equals(other$addGssgId)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        Text this$title = this.getTitle();
        Text other$title = other.getTitle();
        if (this$title == null ? other$title != null : !this$title.equals(other$title)) {
            return false;
        }
        TextField this$addGssgBrName = this.getAddGssgBrName();
        TextField other$addGssgBrName = other.getAddGssgBrName();
        if (this$addGssgBrName == null ? other$addGssgBrName != null : !this$addGssgBrName.equals(other$addGssgBrName)) {
            return false;
        }
        TextField this$addGssgName = this.getAddGssgName();
        TextField other$addGssgName = other.getAddGssgName();
        if (this$addGssgName == null ? other$addGssgName != null : !this$addGssgName.equals(other$addGssgName)) {
            return false;
        }
        TableView<AddShopTableOutData> this$tableView = this.getTableView();
        TableView<AddShopTableOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<AddShopTableOutData, String> this$shopName = this.getShopName();
        TableColumn<AddShopTableOutData, String> other$shopName = other.getShopName();
        if (this$shopName == null ? other$shopName != null : !this$shopName.equals(other$shopName)) {
            return false;
        }
        TableColumn<AddShopTableOutData, String> this$index = this.getIndex();
        TableColumn<AddShopTableOutData, String> other$index = other.getIndex();
        if (this$index == null ? other$index != null : !this$index.equals(other$index)) {
            return false;
        }
        TableColumn<AddShopTableOutData, String> this$shopId = this.getShopId();
        TableColumn<AddShopTableOutData, String> other$shopId = other.getShopId();
        if (this$shopId == null ? other$shopId != null : !this$shopId.equals(other$shopId)) {
            return false;
        }
        ObservableList<AddShopTableOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<AddShopTableOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        ShopSortSettingController this$shopSortSettingController = this.getShopSortSettingController();
        ShopSortSettingController other$shopSortSettingController = other.getShopSortSettingController();
        if (this$shopSortSettingController == null ? other$shopSortSettingController != null : !(this$shopSortSettingController).equals(other$shopSortSettingController)) {
            return false;
        }
        Set<String> this$shopIdsSet = this.getShopIdsSet();
        Set<String> other$shopIdsSet = other.getShopIdsSet();
        if (this$shopIdsSet == null ? other$shopIdsSet != null : !(this$shopIdsSet).equals(other$shopIdsSet)) {
            return false;
        }
        String this$shopIdSelect = this.getShopIdSelect();
        String other$shopIdSelect = other.getShopIdSelect();
        if (this$shopIdSelect == null ? other$shopIdSelect != null : !this$shopIdSelect.equals(other$shopIdSelect)) {
            return false;
        }
        String this$titleTemp = this.getTitleTemp();
        String other$titleTemp = other.getTitleTemp();
        if (this$titleTemp == null ? other$titleTemp != null : !this$titleTemp.equals(other$titleTemp)) {
            return false;
        }
        Boolean this$type = this.getType();
        Boolean other$type = other.getType();
        if (this$type == null ? other$type != null : !(this$type).equals(other$type)) {
            return false;
        }
        Timer this$timer = this.getTimer();
        Timer other$timer = other.getTimer();
        return !(this$timer == null ? other$timer != null : !this$timer.equals(other$timer));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddShopSortController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        SearchTextField $addGssgBrId = this.getAddGssgBrId();
        result = result * 59 + ($addGssgBrId == null ? 43 : (($addGssgBrId)).hashCode());
        TextField $addGssgId = this.getAddGssgId();
        result = result * 59 + ($addGssgId == null ? 43 : $addGssgId.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        Text $title = this.getTitle();
        result = result * 59 + ($title == null ? 43 : $title.hashCode());
        TextField $addGssgBrName = this.getAddGssgBrName();
        result = result * 59 + ($addGssgBrName == null ? 43 : $addGssgBrName.hashCode());
        TextField $addGssgName = this.getAddGssgName();
        result = result * 59 + ($addGssgName == null ? 43 : $addGssgName.hashCode());
        TableView<AddShopTableOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<AddShopTableOutData, String> $shopName = this.getShopName();
        result = result * 59 + ($shopName == null ? 43 : $shopName.hashCode());
        TableColumn<AddShopTableOutData, String> $index = this.getIndex();
        result = result * 59 + ($index == null ? 43 : $index.hashCode());
        TableColumn<AddShopTableOutData, String> $shopId = this.getShopId();
        result = result * 59 + ($shopId == null ? 43 : $shopId.hashCode());
        ObservableList<AddShopTableOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        ShopSortSettingController $shopSortSettingController = this.getShopSortSettingController();
        result = result * 59 + ($shopSortSettingController == null ? 43 : ($shopSortSettingController).hashCode());
        Set<String> $shopIdsSet = this.getShopIdsSet();
        result = result * 59 + ($shopIdsSet == null ? 43 : ($shopIdsSet).hashCode());
        String $shopIdSelect = this.getShopIdSelect();
        result = result * 59 + ($shopIdSelect == null ? 43 : $shopIdSelect.hashCode());
        String $titleTemp = this.getTitleTemp();
        result = result * 59 + ($titleTemp == null ? 43 : $titleTemp.hashCode());
        Boolean $type = this.getType();
        result = result * 59 + ($type == null ? 43 : ($type).hashCode());
        Timer $timer = this.getTimer();
        result = result * 59 + ($timer == null ? 43 : $timer.hashCode());
        return result;
    }

    public String toString() {
        return "AddShopSortController(addGssgBrId=" + (this.getAddGssgBrId()) + ", addGssgId=" + this.getAddGssgId() + ", pane=" + this.getPane() + ", title=" + this.getTitle() + ", addGssgBrName=" + this.getAddGssgBrName() + ", addGssgName=" + this.getAddGssgName() + ", tableView=" + this.getTableView() + ", shopName=" + this.getShopName() + ", index=" + this.getIndex() + ", shopId=" + this.getShopId() + ", observableTableList=" + this.getObservableTableList() + ", shopSortSettingController=" + this.getShopSortSettingController() + ", shopIdsSet=" + this.getShopIdsSet() + ", shopIdSelect=" + this.getShopIdSelect() + ", titleTemp=" + this.getTitleTemp() + ", type=" + this.getType() + ", timer=" + this.getTimer() + ")";
    }
}

